package br.com.mtg.movethegarbage.screens;

import br.com.mtg.movethegarbage.framework.Game;
import br.com.mtg.movethegarbage.framework.GameTouchEvent;
import br.com.mtg.movethegarbage.framework.Input;
import br.com.mtg.movethegarbage.framework.Screen;
import br.com.mtg.movethegarbage.game.Assets;
import br.com.mtg.movethegarbage.game.Levels;
import br.com.mtg.movethegarbage.graphics.Camera2D;
import br.com.mtg.movethegarbage.graphics.SpriteManager;

public class HintScreen extends Screen
{
	long timer;
	Camera2D cam;
	String hint;
	int mapLvl;

	public HintScreen(Game _game, int lvl)
	{
		super(_game);
		mapLvl = lvl;
		hint = Levels.getHint(game, mapLvl);
		cam = new Camera2D(game.getGraphics());
	}

	@Override
	public void update(long delta)
	{
		Input input = game.getInput();
		synchronized (input)
		{
			for(GameTouchEvent e : input.getTouchEvents())
				if(e.type == GameTouchEvent.TOUCH_DOWN)
				{
					game.setScreen(new GameScreen(game, mapLvl));
					return;
				}
		}
		timer += delta;
		if (timer >= 6000)
			game.setScreen(new GameScreen(game, mapLvl));
	}

	@Override
	public void present(long delta)
	{
		SpriteManager spriteManager = new SpriteManager(game.getGraphics(), 1);
		spriteManager.beginDraw(Assets.tex_backgroundScreenRedMain);
		spriteManager.drawSprite(0, 0, width, height, Assets.background);
		spriteManager.endDraw();

		Assets.font.setScale(0.5F * multiplier);
		String[] words = hint.split(";");
		float stringWidth;
		for (int i = 0; i < words.length; i++)
		{
			stringWidth = Assets.font.getTextLength(words[i]);
			Assets.font.printAt(words[i], (width - stringWidth) / 2, height - (i + 1) * Assets.font.getTextHeight());
		}
	}

	@Override
	public void pause()
	{
	}

	@Override
	public void resume()
	{
		cam.setViewAndMatrices();

		game.getGraphics().initialize();

		width = game.getGraphics().getWidth();
		height = game.getGraphics().getHeight();
		multiplier = game.getGraphics().getMultiplier();
	}

	@Override
	public void dispose()
	{
	}

}
